import {fileURLToPath,pathToFileURL} from 'url'
import fs from 'fs'

/**
 * 
 * 
 * @returns {array}-所有的控制器路径，形式为：['file:///c://users/administrator/desktop/23级全栈1班/controllers/blogs.js', 'file:///c://users/administrator/desktop/23级全栈1班/controllers/books.js']
 */
export const findAllControllerFiles = function(){
    let baseControllerUer=new URL('../controllers',import.meta.url).href

    let baseControllerPath= fileURLToPath(baseControllerUer)
    let allFiles = fs.readFileSync(baseControllerPath)

    let allControllerFiles = allFiles.filter(item=>item.endsWith('.js'))
      .map(item=>pathToFileURL(`${baseControllerPath}/${item}`.href))

    return allControllerFiles;  

}




/**
 * 
 * @param {array} controllers 所有控制器文件的路径['file:///c://users/administrator/desktop/23级全栈1班/controllers/blogs.js']
 * @returns {void}没有返回值
 * 
 */
